package com.crealth.memcached;

import java.util.List;

import com.crealth.db.ConsumerDb;
import com.crealth.model.ConsumerCarModel;


public class ConsumerCarCached {
	private static final String carKeyPrefix = "car_csmid_";
	
	@SuppressWarnings("unchecked")
	public static List<ConsumerCarModel> selectConsumerCar(int consumerID) {
		String key = carKeyPrefix + consumerID;
		Object obj = MemcachedMgr.cachedClient.get(key);
		List<ConsumerCarModel> carls = null;
		if (obj != null) {
			carls = (List<ConsumerCarModel>)obj;
		}
		else {
			carls = ConsumerDb.selectConsumerCar(consumerID);
			if (carls != null) {
				MemcachedMgr.cachedClient.set(key, carls);
			}
		}
		
		return carls;
	}
	
	public static void deleteCached(int consumerID) {
		String key = carKeyPrefix + consumerID;
		MemcachedMgr.cachedClient.delete(key);
	}
	
}
